18.5.4 Argument Qualifiers
Anywhere a parameter name can appear in the
parameter list you can also use an argument qualifier.
Thus the general form of a definition is:
(defmath name (param param...
&optional param param...
&rest param)
body)
where each param is either a
symbol or a list of the form
(qual param)
The following qualifiers are recognized:
- ‘complete’
- The argument must not be an
incomplete vector, interval, or complex number. (This is rarely
needed since the Calculator itself will never call your
function with an incomplete argument. But there is nothing
stopping your own Lisp code from calling your function with an
incomplete argument.)
- ‘integer’
- The argument must be an integer. If it
is an integer-valued float it will be accepted but converted to
integer form. Non-integers and formulas are
rejected.
- ‘natnum’
- Like
‘integer’,
but the argument must be non-negative.
- ‘fixnum’
- Like
‘integer’,
but the argument must fit into a native Lisp integer, which on
most systems means less than 2^23 in absolute value. The
argument is converted into Lisp-integer form if
necessary.
- ‘float’
- The
argument is converted to floating-point format if it is a
number or vector. If it is a formula it is left alone. (The
argument is never actually rejected by this
qualifier.)
- ‘pred’
- The argument must satisfy predicate pred, which
is one of the standard Calculator predicates. See Predicates.
- ‘not-pred’
- The argument must not satisfy predicate
pred.
For example,
(defmath foo (a (constp (not-matrixp b)) &optional (float c)
&rest (integer d))
body)
expands to
(defun calcFunc-foo (a b &optional c &rest d)
(and (math-matrixp b)
(math-reject-arg b 'not-matrixp))
(or (math-constp b)
(math-reject-arg b 'constp))
(and c (setq c (math-check-float c)))
(setq d (mapcar 'math-check-integer d))
body)
which performs the necessary checks and
conversions before executing the body of the function.